import json


class Response(json.JSONEncoder):

    def __init__(self):
        super().__init__()
        self.code = 0
        self.msg = ''
        self.data = []

    def error(self, code, message):
        self.code = code
        self.msg = message
        self.data = []

    def success(self, message, data):
        self.code = 1
        self.msg = message
        self.data = data

    def to_dict(self):
        return {
            'code': self.code,
            'msg': self.msg,
            'data': self.data
        }
